import { useCallback, useState } from 'react';
import { getItem, removeItem } from "../utils";

export const useLocalStorage = () => {
  const [sd, setSd] = useState('')

  const lsGetItem = useCallback((key: string) => {
    getItem(key)
      .then((d) => {
        if (d) {
          setSd(JSON.parse(JSON.stringify(d)))
        }
      })
      .catch(() => { })
  }, [])
  
  const lsRemoveItem = useCallback((key: string) => {
    removeItem(key)
      .then(() => {
        setSd('')
      })
      .catch(() => { })
  }, []) 
  
  return { lsGetItem, lsRemoveItem, sd }
}

